package cn.memedai.router.matcher;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;

import androidx.annotation.Nullable;

import java.util.Map;
import java.util.Set;

import cn.memedai.router.RouteOptions;

/**
 * Absolutely matcher.
 * <p>
 * Created by Cheney on 2016/12/23.
 */
public class DirectMatcher extends AbsExplicitMatcher {

    public DirectMatcher(int priority) {
        super(priority);
    }

    @Override
    public MatcherResult match(Context context, Uri uri, @Nullable Map<String, Class<? extends Activity>> activityTable, RouteOptions routeOptions) {
        MatcherResult matcherResult = MatcherResult.newInstance();
        Set<Map.Entry<String, Class<? extends Activity>>> entries = activityTable.entrySet();
        String route = null;
        for (Map.Entry<String, Class<? extends Activity>> entry : entries) {
            route = entry.getKey();
            if(!isEmpty(route) && uri.toString().equals(route)){
                matcherResult.setMatch(true);
                matcherResult.setMatchClass(entry.getValue());
                return matcherResult;
            }
        }
        return matcherResult;
    }
}
